<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use DB;

class JianyiController extends Controller
{
    
	/*
		留言列表
	*/
	public function getIndex(Request $request)
	{
		// $jianyi = DB::table('shop_jianyi')->get();
		//获取每页显示条数
		$num = $request->input('num',10);
		
		//获取参数列表
		$list = $request->all();

		//判断是否有查询条件
		if($request->input('keywords')){
			$jianyi = DB::table('shop_jianyi')->where('uname','like','%'.$request->input('keywords').'%')->paginate($num);
		}else{
			$jianyi = DB::table('shop_jianyi')->paginate($num);
		}
		
		// //解析模板
		return view('admin.jianyi.index',['jianyi'=>$jianyi,'list'=>$list,'num'=>$num]);
	} 

	
	/*
		留言删除
	*/
	public function postDelete(Request $request)
	{
		//获取id
		$id = $request->input('id');

		//删除数据库
		$res = DB::table('shop_jianyi')->where('id',$id)->delete();
		//返回给ajax
		echo $res;
	}

}
